#ifndef SIPDLGSESSIONBASE_HPP__
#define SIPDLGSESSIONBASE_HPP__

#include "WTResipDll/SipWTResipDllItf.hpp"

#include "WTSXSipService/SipWTSXServiceItf.hpp"
#include "WTSXSipService/SipSessionBase.hpp"

#include <boost/thread/mutex.hpp>

namespace wtsxsip{


class CSipTranSession;

class CSipDlgSessionBase: 
    public ISipDlgSessionBase,
    public ISipTranSessionHandle,
    public CSipSessionBase,
    public wtsip::ISipDlgHandle    
{
public:

    CSipDlgSessionBase(CSipSessionMgr& mgr, uint32_t id, wtsip::ISipDialogBase& dlg, const wtsip::SUri& tar);

    CSipDlgSessionBase(CSipSessionMgr& mgr, uint32_t id, wtsip::ISipDialogBase& dlg, 
        const wtsip::SUri& tar, ISipTranSession& tran);

    virtual ~CSipDlgSessionBase();

    virtual uint32_t getHandle();

    virtual EDlgSessionState getState();

    virtual bool cancel();

    virtual bool send(SHeaders& headers, const SMsgBodyBase& body, uint32_t& id);

    virtual bool stop();

    virtual bool registerHandle(ISipDlgSessionBaseHandle* h);

    virtual bool unregisterHandle(ISipDlgSessionBaseHandle* h);

    virtual bool messageDress(wtsip::CSipMessage& msg);

    virtual bool setState(EDlgSessionState nState);

    virtual bool onDestroy();

    virtual bool insert(ISipTranSession* tran);

    virtual bool earase(ISipTranSession* tran);

    //////////////////////// wtsip::Dialog Handle ///////////////////////

    virtual bool onRequest(wtsip::ISipDialogBase& dlg, wtsip::ISipSrvTransaction& srv, wtsip::CapSipMessage msg);

    virtual bool onDestroy(wtsip::ISipDialogBase& dlg);

    //////////////////////// Tran session Handle ////////////////////////

    virtual bool onRequest(ISipTranSession& tran, const SHeaders& headers, const SMsgBodyBase& body);

    virtual bool onResponse(ISipTranSession& tran, const SHeaders& headers, const SMsgBodyBase& body);

    virtual bool onState(ISipTranSession& tran, const ISipTranSession::ETranSessionState newState);

    virtual bool onDestroy(ISipTranSession& tran);

    /////////////////////// This session handle methods ///////////////////    

    virtual bool handleRequest(const SHeaders& headers, const SMsgBodyBase& body, ISipTranSession& srvTran);

    virtual bool handleResponse(const SHeaders& headers, const SMsgBodyBase& body, ISipTranSession& clnTran);

    virtual bool handleState(const EDlgSessionState newState);

    virtual bool handleDestroy(ISipTranSession& tran);

    virtual bool handleDestroy();

protected:

    wtsip::ISipDialogBase* m_dialog;

    wtsip::SUri m_tar;

    wtsip::EMethodTypes m_keyMethod;

    uint32_t m_keyTranId;

    std::set<uint32_t> m_tranSessions;

    std::vector<ISipDlgSessionBaseHandle*> m_handles;

    boost::mutex m_sessionsMutex;

    EDlgSessionState m_state;

};


}//namespace

#endif

